/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Branchesform.java
 *
 * Created on Oct 18, 2011, 9:59:15 AM
 */
package project;

import Utils.Helper;
import Utils.checkValidate;
import beanControl.branchesControl;
import beanInfo.branches;

/**
 *
 * @author lyan
 */
public class Branchesform extends javax.swing.JFrame {

    branches bra = new branches();
    branchesControl bract = new branchesControl();
    String id="";
    /** Creates new form Branchesform */
    public Branchesform(String ID) {
        initComponents();
        this.id=ID;
        lblBranchesID.setText(id);
        txtAddress.setText(id);
        txtBranchName.setText(id);
        txtEmail.setText(id);
    }

    public void insertBranches() {
        bra.setBranchesName(txtBranchName.getText());
        bra.setAddress(txtAddress.getText());
        bra.setEmail(txtEmail.getText());
        bract.insertbranches(bra);
    }

    public void updatebranches() {
        bra.setBranchesName(txtBranchName.getText());
        bra.setAddress(txtAddress.getText());
        bra.setEmail(txtEmail.getText());
        bract.updatebranches(bra);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblBranchesID = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtBranchName = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 102, 102));
        jPanel1.setLayout(null);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setLayout(null);
        jPanel2.add(lblBranchesID);
        lblBranchesID.setBounds(30, 80, 34, 14);

        jLabel2.setText("BranchName");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(30, 120, 70, 30);

        jLabel3.setText("Address");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(30, 170, 70, 30);

        jLabel4.setText("Email");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(30, 210, 50, 20);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 36));
        jLabel5.setForeground(new java.awt.Color(255, 0, 0));
        jLabel5.setText("Branches");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(100, 10, 260, 70);
        jPanel2.add(txtBranchName);
        txtBranchName.setBounds(110, 120, 230, 30);
        jPanel2.add(txtAddress);
        txtAddress.setBounds(110, 170, 230, 30);
        jPanel2.add(txtEmail);
        txtEmail.setBounds(110, 210, 230, 30);

        btnSave.setBackground(new java.awt.Color(0, 102, 102));
        btnSave.setForeground(new java.awt.Color(255, 255, 255));
        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        jPanel2.add(btnSave);
        btnSave.setBounds(130, 270, 60, 30);

        btnCancel.setBackground(new java.awt.Color(0, 102, 102));
        btnCancel.setForeground(new java.awt.Color(255, 255, 255));
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancel);
        btnCancel.setBounds(220, 270, 70, 30);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(10, 10, 400, 340);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed

    if (txtBranchName.getText().length() == 0) {
        Helper.successMessage("Branches does not exited", "wanning");

    } else if (txtAddress.getText().length() == 0) {
        Helper.successMessage("Address does not Exited", "wanning");
    } else if (txtEmail.getText().length() == 0) {
        Helper.successMessage("email does not Exited", "wanning");

    } else if (checkValidate.isEmail(txtEmail.getText()) == false) {
        Helper.successMessage("Email Invalid", null);
    } else {
        insertBranches();
    }
}//GEN-LAST:event_btnSaveActionPerformed

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_btnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(Branchesform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(Branchesform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(Branchesform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(Branchesform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new Branchesform().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnSave;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblBranchesID;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtBranchName;
    private javax.swing.JTextField txtEmail;
    // End of variables declaration//GEN-END:variables
}
